<template>
	<view class="container">
		<tui-list-cell :hover="false">
			<view class="tui-goods__box">
				<image :src="'http://192.168.2.94'+orderDetail.goods_image" class="tui-goods__img" mode="widthFix">
				</image>
				<view class="tui-rate__box">
					<view class="tui-rate__text">商品评分</view>
					<view class="tui-rate__text" style="display: flex;align-items: center;">
						<view class="tui-rate__text" style="color: red;">￥{{ orderDetail.goods_price }}</view>
						<view class="tui-rate__text" style="margin-left: 10rpx;color: #999;">
							×{{ orderDetail.goods_num }}</view>
					</view>


					<!-- <tui-rate :current="current" @change="change"></tui-rate> -->
				</view>
			</view>
		</tui-list-cell>
		<tui-list-cell :hover="false">
			<view class="tui-rate__box" style="display: flex;align-items: center;padding-left: 5rpx;">
				<view class="" style="font-size: 30rpx;font-weight: bold;margin-right: 15rpx;">商品评分</view>
				<tui-rate :current="level" @change="change" :size="22"></tui-rate>
			</view>
		</tui-list-cell>
		<tui-list-cell :hover="false" padding="0">
			<textarea class="tui-textarea" placeholder="产品怎么样,说说优缺点..." v-model="content" maxlength="200"></textarea>
		</tui-list-cell>
		<tui-list-cell :hover="false">
			<view class="tui-img__title">添加图片</view>
			<!-- <tui-upload></tui-upload> -->
			<!-- <tui-upload :value="value" @complete="complete" :formData="formData" :serverUrl="serverUrl" @remove="remove"></tui-upload> -->
			<tn-image-upload ref="imageUpload" :action="serverUrl" :maxCount="9" :header="header" :formData="formData"
				@on-success="onSuccess"></tn-image-upload>

		</tui-list-cell>
		<!-- <view class="tui-check__box">
			<checkbox-group>
				<label class="tui-checkbox">
					<checkbox color="#fff"></checkbox>
					<text class="tui-cb__text">匿名评价</text>
				</label>
			</checkbox-group>
		</view> -->

		<view class="tui-btn__box">
			<tui-button type="danger" height="88rpx" shape="circle" @click="sumbit">提交评价</tui-button>
		</view>
	</view>
</template>

<script>
	import {
		getOrderDetail,
		getOrderComment
	} from "@/apis/index"
	import {
		getToken
	} from "@/util/auth"
	export default {
		data() {
			return {
				level: 5,
				orderDetail: {},
				mageData: [],
				content:"",
				//上传接口地址
				serverUrl: "https://www.taoding1688.com/api/common/upload",
				value: [], //初始化图片
				header: {
					'token': getToken()
				},
				formData: {
					'group': 'ugc', // 其他要传的参数
				},
				list:[],
				detail:{}
			}
		},
		onLoad(option) {
			getOrderDetail(option.order_sn).then(res => {
				this.orderDetail = res.data.items[0]
				this.detail=res.data
			})
		},
		methods: {
			change(e) {
				this.level = e.index
			},
			result: function(e) {
				// this.imageData = e.imgArr;
			},
			remove: function(e) {
				//移除图片
				let index = e.index
			},
			onSuccess(data, index, lists, name) {
				this.list = lists.map(item => {
					return item.response.data.url
				})
			},
			sumbit(){
				
				
				let obj={
				    "comments": [
				        {
				            "item_id": this.orderDetail.id,
				            "level": this.level,
				            "content": this.content,
				            "images":this.list
				        }
				    ]
				}
				getOrderComment(obj,this.detail.id).then(res=>{
					if (res.code==1) {
						uni.navigateBack({
							delta:1
						})
					}
				})
			}
		}
	}
</script>

<style>
	.container {
		padding: 20rpx 0;
	}

	.tui-goods__box {
		width: 100%;
		display: flex;
		align-items: center;
	}

	.tui-goods__img {
		width: 144rpx;
		height: 144rpx;
	}

	.tui-rate__box {
		flex: 1;
		height: 100%;
		padding-left: 20rpx;
		font-size: 26rpx;
	}

	.tui-rate__text {
		margin-bottom: 16rpx;
	}

	.tui-textarea {
		width: 100%;
		height: 300rpx;
		font-size: 28rpx;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		background-color: #fff;
	}

	.tui-img__title {
		padding-bottom: 24rpx;
	}

	.tui-check__box {
		padding: 25rpx 30rpx;
	}

	.tui-checkbox {
		min-width: 70rpx;
		height: 45rpx;
		display: flex;
		align-items: center;
	}

	/* #ifdef MP-WEIXIN */
	.tui-checkbox .wx-checkbox-input {
		width: 40rpx;
		height: 40rpx;
		margin-right: 0 !important;
		border-radius: 50% !important;
		transform: scale(0.8);
		transform-origin: center 30%;
		border-color: #d1d1d1 !important;
	}

	.tui-checkbox .wx-checkbox-input.wx-checkbox-input-checked {
		background: #eb0909;
		width: 44rpx !important;
		height: 44rpx !important;
		border: none;
	}

	/* #endif */
	/* #ifndef MP-WEIXIN */

	>>>.tui-checkbox .uni-checkbox-input {
		width: 40rpx;
		height: 40rpx;
		margin-right: 0 !important;
		border-radius: 50% !important;
		transform: scale(0.8);
		border-color: #d1d1d1 !important;
	}

	>>>.tui-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
		background: #eb0909;
		width: 45rpx !important;
		height: 45rpx !important;
		border: none;
	}

	/* #endif */

	.tui-cb__text {
		font-size: 28rpx;
		padding-left: 8rpx;
		color: #999;
	}

	.tui-btn__box {
		width: 100%;
		padding: 40rpx 30rpx;
		box-sizing: border-box;
	}
</style>